package com.woniu.humanresource.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.humanresource.dao.AttendanceParametersMapper;
import com.woniu.humanresource.entity.AttendanceParameters;
import com.woniu.humanresource.entity.Contract;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.AttendanceParametersService;
//import com.woniu.humanresource.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyq
 * @since 2022-07-04
 */
@Slf4j
@RestController
@RequestMapping("/humanresource/attendance-parameters")
public class AttendanceParametersController {
    @Resource
    AttendanceParametersService attendanceParametersService;

    @PostMapping("/insert")
    public ResponseText add(@RequestBody AttendanceParameters attendanceParameters){
        log .info("aaa");
        log.info(attendanceParameters.toString());
        boolean b = attendanceParametersService.save(attendanceParameters);
        attendanceParameters.setUpdater(attendanceParameters.getFounder());
        attendanceParametersService.updateById(attendanceParameters);
        return new ResponseText(b,200,"success");
    }
    @DeleteMapping("/deleteById/{id}")
    public ResponseText delete(@PathVariable("id")int id){
        boolean b = attendanceParametersService.removeById(id);
        return new ResponseText(b,200,"success");
    }
    @PutMapping("/update")
    public ResponseText update(@RequestBody AttendanceParameters attendanceParameters){
        boolean b = attendanceParametersService.updateById(attendanceParameters);
        return new ResponseText(b,200,"success");
    }
    @RequestMapping("/findAllparameters")
    public ResponseText<AttendanceParameters> all(){

        List<AttendanceParameters> list = attendanceParametersService.list(null);
        return new ResponseText(list, 200,"success");
    }

    /**
     * 单表模糊查询，通过模糊参数名称来查
     * @param parameterName2
     * @return
     */
    @GetMapping("/findLikeparameters")
    public ResponseText<List<AttendanceParameters>> like( String parameterName2){
        log.info("前端传递的参数为:{}",parameterName2);
        //如果为空，则返回所有
        if (StringUtils.isBlank(parameterName2)){
            List<AttendanceParameters> list = this.attendanceParametersService.list(null);
            return new ResponseText(list, 200, "can't find");
        }
        LambdaQueryWrapper<AttendanceParameters> queryWrapper =new LambdaQueryWrapper<>();

        queryWrapper.like(AttendanceParameters::getParameterName,parameterName2);

        List<AttendanceParameters> list = this.attendanceParametersService.list(queryWrapper);

        //return ResponseUtil.success(list);
        return new ResponseText(list, 200, "success");
    }

}

